<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>

</body>
<script>
    let arr = [1, 23, 1, 1, 1, 3, 23, 5, 6, 7, 9, 9, 8, 5];

    function rep(arr) {
        let ret = [];
        for (var i = 0; i < arr.length; i++) {


            // indexOf 返回的是下标 比如 arr.indexOf(23) 返回的是1 而且是从数组最开始检查有就立刻返回
            if (arr.indexOf(arr[i]) == i) {

                ret.push(arr[i]);
            }
        }
        return ret;
    }
    let arr2 = rep(arr);
    console.log(arr); // [1, 23, 1, 1, 1, 3, 23, 5, 6, 7, 9, 9, 8, 5]
    console.log(arr2); // [1, 23, 3, 5, 6, 7, 9, 8]
</script>

</html>